package org.NooLab.itexx.app.gui.handlers.keys;

import java.awt.ItemSelectable;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import javax.swing.JComponent;

import org.NooLab.itexx.app.gui.definition.ITexxWindowGui2;
import org.NooLab.itexx.app.gui.definition.ITexxWindowGuiIntf;
import org.NooLab.utilities.logging.PrintLog;
import org.apache.commons.collections.BidiMap;
import org.apache.commons.collections.bidimap.DualHashBidiMap;




public class Keyhandlers  {

	public static final int _CFK_CTRL   = 1;
	public static final int _CFK_ALT    = 2;
	public static final int _CFK_SHIFT  = 3;
	public static final int _CFK_OPTION = 4;
	
	// ..........................................
	
	ITexxWindowGuiIntf windowGui;
	
	ArrayList<Keyhandler> items = new ArrayList<Keyhandler>();

	BidiMap itemsMap = new DualHashBidiMap();   
	// <Integer,Object>
	private String[] globalKeys ;
	
	
	
	PrintLog out = new PrintLog(2,false);

	private ItexxGuiKeyListener appKeyListener;

	Map<String, Integer> globalActionCodeMapping = new HashMap<String, Integer>();

	private int currentControlFunctionKey;
	private long functionKeyTime;
	
	// ========================================================================
	public Keyhandlers(ITexxWindowGuiIntf gui) {
		// 
		windowGui = gui;
	}


	public void close(){
		
	}
	
	public Keyhandler create(int id) {
		// 
		Keyhandler keyHandler = new Keyhandler( this, id, globalKeys );
		items.add(keyHandler);
		itemsMap.put(id, keyHandler ) ;
		
		return keyHandler ;
	}

	public void setGlobalKeys(String[] inkeys) {
		//
		globalKeys = new String[ inkeys.length ];
		System.arraycopy(inkeys, 0, globalKeys, 0, globalKeys.length) ;
	}

	

	public void setAppKeyListener(ItexxGuiKeyListener keyListener) {
		// 
		appKeyListener = keyListener ;
	}

	public ItexxGuiKeyListener getAppKeyListener() {
		return appKeyListener;
	}

	// instead of integer, there could also be a parameter object... later...
	public Map<String,Integer> getGlobalKeyActionCodeMapping() {
		// 
		return globalActionCodeMapping;
	}
	
	public int getCurrentControlFunctionKey(){
		return currentControlFunctionKey ;
	}


	public void setCurrentControlFunctionKey(int cfKeyId, long keyTime) {
		this.currentControlFunctionKey = cfKeyId;
		functionKeyTime = keyTime;
	}


	public long getFunctionKeyTime() {
		return functionKeyTime;
	}

}
